﻿using DotNetHackathon.GBA.ApiCommon.JsonSerializing;

namespace DotNetHackathon.GBA.ApiCommon.ExceptionHandling
{
    public class DefaultExceptionToResponseTextConverter : IExceptionToResponseTextConverter
    {
        protected IJsonSerializer JsonSerializer { get; }

        protected IExceptionToErrorResultConverter ExceptionToErrorInfoConverter { get; }

        public DefaultExceptionToResponseTextConverter(IJsonSerializer jsonSerializer,
            IExceptionToErrorResultConverter exceptionToErrorInfoConverter)
        {
            JsonSerializer = jsonSerializer;
            ExceptionToErrorInfoConverter = exceptionToErrorInfoConverter;
        }

        public virtual string Convert(Exception exception)
        {
            var errorResult = ExceptionToErrorInfoConverter.Convert(exception);
            return JsonSerializer.Serialize(errorResult);
        }
    }
}
